//
//  MeatMapBottomer.m
//  PigMarket
//
//  Created by 张敬 on 2019/8/2.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "MeatMapBottomer.h"

@interface MeatMapBottomer()

/**
 MeatMapBottomer 's HistoryScrollView -> UIScrollView
 */
@property (nonatomic, strong) UIScrollView *historyScrollView;

@end


@implementation MeatMapBottomer

#pragma mark - lifecycle methods

- (void)setupUI{
    
    self.backgroundColor = KWhiteColor;
    [self addTitles];
    [self addSubview:self.historyScrollView];
}

- (void)setupLayout{
    
    self.height = 187;
    
    {
        _historyScrollView.mj_x = 15;
        _historyScrollView.mj_y = self.height - 60;
        _historyScrollView.width = KScreenWidth - 15;
        _historyScrollView.height = 40;
    }

}


- (void)addTitles{
    
    NSArray *titles = @[@"  武清区创业总部基地", @"  输入您的收货位置"];
    NSArray *colors = @[UIColorFromRGB(0x666666), UIColorFromRGB(0xB2B2B2)];
    NSArray *icons = @[@"meat_map_greencircle", @"meat_map_yellowlocation"];
    
    @weakify(self);
    [titles enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        @strongify(self);
        
        UILabel *label = [UILabel makeLabelWithText:obj textColor:colors[idx] font:mFont(14) textAliment:0];
        label.size = CGSizeMake(KScreenWidth - 47, 40);
        label.mj_x = 37;
        label.mj_y = 15 + (label.height + 10)*idx;
        label.backgroundColor = mBackgroudColor;
        [self addShadowAndCircleCorner:label.layer corner:5];
        [self addSubview:label];
        
        if (idx == 0) {
            UIImageView *resetIcon = [UIImageView makeImageByImageName:@"meat_map_resetlocation" cornerRadius:0];
            resetIcon.size = CGSizeMake(40, 40);
            resetIcon.mj_y = 0;
            resetIcon.mj_x = label.width - resetIcon.width;
            [label addSubview:resetIcon];
            
            resetIcon.tapBlock = ^{
                
                if (self.dealResetLocationBlock) {
                    self.dealResetLocationBlock();
                }
            };
            
        }else{
            
            label.tapBlock = ^{
                
                if (self.dealInputLocationBlock) {
                    self.dealInputLocationBlock();
                }
            };
        }
        
        UIImageView *icon = [UIImageView makeImageByImageName:icons[idx] cornerRadius:0];
        icon.size = CGSizeMake(37, 40);
        icon.mj_x = 0;
        icon.mj_y = label.mj_y;
        [self addSubview:icon];
        
    }];
}

#pragma mark - setter methods


#pragma mark - getter methods

- (UIScrollView *)historyScrollView{
    
    if(!_historyScrollView){
        
        _historyScrollView = [[UIScrollView alloc] init];
        _historyScrollView.backgroundColor = KWhiteColor;
        _historyScrollView.showsHorizontalScrollIndicator = NO;
        
        NSArray *array = @[@"我的猪小铺",@"行走的裤子",@"一口线",@"剪刀石头锤子",@"武清区先伸得很简单",@"哈睡觉啊就睡觉",@"阿睡觉睡觉啊就睡觉啊"];
        CGFloat buttonX = 0;
        CGFloat buttonSpace = 5;
        
        for(NSInteger i=0; i<array.count; i++){
            
            NSString *string = array[i];
            CGSize size = [string sizeWithFont:mFont(16)];
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            [button setTitle:string forState:UIControlStateNormal];
            [button setTitleColor:UIColorFromRGB(0x9C9C9C) forState:UIControlStateNormal];
            button.titleLabel.font = mFont(12);
            button.frame = CGRectMake(buttonX, 5, size.width, 28);
            [self addShadowAndCircleCorner:button.layer corner:14];
            button.layer.borderColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.16].CGColor;
            button.layer.borderWidth = 1;
            [self.historyScrollView addSubview:button];
            buttonX += buttonSpace + size.width;
            
            @weakify(self);
            button.tapBlock = ^{
                @strongify(self);
                
                if (self.dealHistoryLocationBlock) {
                    self.dealHistoryLocationBlock(i);
                }
            };
        }
        
        CGFloat contentX = buttonX > self.historyScrollView.bounds.size.width ? buttonX :self.historyScrollView.bounds.size.width;
        self.historyScrollView.contentSize = CGSizeMake(contentX, 0);
    }
    return _historyScrollView;
}


@end
